package com.another.bidservice.controller;

import com.another.bidservice.entity.TColumn;
import com.another.bidservice.service.IColumnService;
import com.another.common.utils.common.MyException;
import org.apache.log4j.Logger;
import com.another.common.utils.result.Result;
import com.another.common.utils.result.ResultEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/column")
@CrossOrigin
public class ColumnController {

    private Logger logger=Logger.getLogger(this.getClass());

    @Autowired
    private IColumnService iColumnService;

    @PostMapping(value = "/getList")
    @ResponseBody
    public Result getList(@RequestBody TColumn tColumn) {
       try {
            return iColumnService.getList(tColumn);
        } catch (MyException me) {
            logger.info(me.getMessage(),me);
            return Result.error(me.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            return Result.error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
        }
    }

    @PostMapping(value = "/deleteList")
    @ResponseBody
    public Result deleteList(@RequestBody List<Integer> rowids) {
        try {
            return iColumnService.deleteList(rowids);
        } catch (MyException me) {
            logger.info(me.getMessage(),me);
            return Result.error(me.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            return Result.error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
        }
    }

    @PostMapping(value = "/insertList")
    @ResponseBody
    public Result insertList(@RequestBody List<TColumn> tColumns) {
        try {
            return iColumnService.insertList(tColumns);
        } catch (MyException me) {
            logger.info(me.getMessage(),me);
            return Result.error(me.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            return Result.error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
        }
    }

    @PostMapping(value = "/updateList")
    @ResponseBody
    public Result updateList(@RequestBody List<TColumn> tColumns) {
        try {
            return iColumnService.updateList(tColumns);
        } catch (MyException me) {
            logger.info(me.getMessage(),me);
            return Result.error(me.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            return Result.error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
        }
    }
    
    @PostMapping(value = "/updateColumn")
    @ResponseBody
    public Result updateColumn(@RequestBody TColumn tColumn) {
        try {
            return iColumnService.updateColumn(tColumn);
        } catch (MyException me) {
            logger.info(me.getMessage(),me);
            return Result.error(me.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            return Result.error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
        }
    }

    @PostMapping(value = "/insertColumn")
    @ResponseBody
    public Result insertColumn(@RequestBody TColumn tColumn) {
        try {
            return iColumnService.insertColumn(tColumn);
        } catch (MyException me) {
            logger.info(me.getMessage(),me);
            return Result.error(me.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            return Result.error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
        }
    }

    @PostMapping(value = "/deleteColumn")
    @ResponseBody
    public Result deleteColumn(@RequestBody TColumn tColumn) {
        try {
            return iColumnService.deleteColumn(tColumn);
        } catch (MyException me) {
            logger.info(me.getMessage(),me);
            return Result.error(me.getCode(), me.getMessage());
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            return Result.error(ResultEnum.UNKONW_ERROR.getCode(), ResultEnum.UNKONW_ERROR.getMsg());
        }
    }
}



